package com.IO.XuLieHuaLiu;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class D01 {
    public static void main(String[] args) throws IOException {
        /*
        * 自定义对象序列化到文件中，但是对象的个数不确定。
        * */
        
        // 1.序列化多个对象
        Cd01_student s1 = new Cd01_student("zhangsan", 23, "beijing");
        Cd01_student s2 = new Cd01_student("lisi", 24, "shanghai");
        Cd01_student s3 = new Cd01_student("wangwu", 25, "guangzhou");
        ArrayList<Cd01_student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("untitled\\a.txt"));
        oos.writeObject(list);
        oos.close();
    }
}
